package org.jet.emall.rbac.transfer;

import org.jet.emall.rbac.dto.AdminUserViewDTO;
import org.jet.emall.rbac.dto.NewAdminUserDTO;
import org.jet.emall.rbac.dto.UpdateAdminUserDTO;
import org.jet.emall.rbac.po.AdminUser;
import org.jet.emall.rbac.po.AdminUserView;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-04-05 11:16
 */
@Mapper
public interface AdminUserDtoTransfer {
    AdminUserDtoTransfer INSTANCE = Mappers.getMapper(AdminUserDtoTransfer.class);

    /**
     * 将PO转DTO
     * @param adminUserView
     * @return
     */
    @Mapping(target = "password",ignore = true)
    AdminUserViewDTO toDto(AdminUserView adminUserView);

    /**
     * 将PO集合转DTO集合
     * @param adminUserViewList
     * @return
     */
    List<AdminUserViewDTO> toDtoList(List<AdminUserView> adminUserViewList);


    /**
     * 将新建用户DTO转成PO
     * @param newUser
     * @return
     */
    @Mappings({
            @Mapping(target = "id",ignore = true),
            @Mapping(target = "deleted",ignore = true),
            @Mapping(target = "modifiedTime",ignore = true)
    })
    AdminUser toPo(NewAdminUserDTO newUser);

    /**
     *  将新新用户DTO转PO
     * @param updateUser
     * @return
     */
    @Mappings({
            @Mapping(target = "deleted",ignore = true),
            @Mapping(target = "modifiedTime",ignore = true)
    })
    AdminUser toPo(UpdateAdminUserDTO updateUser);
}
